<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/share/_meta.jsp" %>
<%@ include file="/share/_footer.jsp" %>
<style type="text/css">
    .table>tbody>tr>td{
        text-align:center;
    }
</style>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>系统管理中心 <span class="c-gray en">&gt;</span> 管理打印
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container">
    <form id="myform" method="post">
        <%--<div class="codeView docs-example">
           &lt;%&ndash; <input id = "code" type="text" placeholder="账单编号" class="input-text radius size-L" style="width:250px" name="id">
            <div class="form-group">
                <select class="form-control" style="width:250px" name="housingId" id="housingId">
                    <option value=''>所有小区</option>
                    <c:forEach items="${parentList}" var="item">
                        <option value="${item.id}" <c:if test="${query.housingId==item.id }">selected</c:if>>${item.name}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="form-group">
                <select class="form-control shift-info" style="width:250px" name="costType" id = "costType">
                    <option value=''>所有费用类型</option>
                    <c:forEach items="${costList}" var="item">
                        <option value="${item.id}" <c:if test="${query.costType==item.id }">selected</c:if>>${item.name}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="form-group">
                <select class="form-control shift-info" style="width:250px" name="paystatus" id="paystatus">
                    <option value=''>付款状态</option>
                    <option value="0" <c:if test="${query.paystatus == false }">selected</c:if>>未付款</option>
                    <option value="1" <c:if test="${query.paystatus == true }">selected</c:if>>已付款</option>
                </select>
            </div>
            <div class="form-group">
                <select class="form-control shift-info" style="width:250px" name="status" id="status">
                    <option value=''>同步状态</option>
                    <option value="0" <c:if test="${query.status == false }">selected</c:if>>未同步</option>
                    <option value="1" <c:if test="${query.status == true }">selected</c:if>>已同步</option>
                </select>
            </div>
            <br>&ndash;%&gt;
            <div class="form-group mt-20">
                <button type="button" class="btn btn-secondary radius size-L" onclick="query()">查&nbsp;询</button>
                &lt;%&ndash;<button type="button" class="btn btn-secondary radius size-L" onclick="delete()">删&nbsp;除</button>&ndash;%&gt;
            </div>
        </div>--%>

        <div class="panel panel-default mt-20">
            <div class="panel-header">
                数据列表
            </div>
            <div class="panel-body">
                <table class="table table-border table-bordered table-bg table-hover table-sort table-striped">
                    <thead>
                    <tr class="text-c">
                        <%--<th width="25"><input type="checkbox" name="" value=""></th>--%>
                        <th>终端号</th>
                        <th>密钥</th>
                        <th>电话</th>
                        <th>打印名</th>
                        <th>创建时间</th>
                        <th>部门名称</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
                <br>
                <br>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript" src="${pageContext.request.contextPath}/h-ui/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript">

    $(function(){
        queryList();
    })

    function queryList(){
        $(".table-sort").dataTable().fnDestroy();
        $(".table-sort").DataTable({
            bStateSave: !0,
            aoColumnDefs: [{bSortable: false}],
            pageLength: 10,
            searching: false,
            bFilter: false,
            bSort:false,
            aLengthMenu:[10],
            serverSide:true,//实现后台分页
            lengthChange: false,
            bPaginate: true,
            ajax: {
                url: "${pageContext.request.contextPath}/rest/printinfo/selectAllList",
                dataSrc: "data",
                data: function ( d ) {

                }
            },
            aoColumns: [//列绑定
                /*{"data": "id"},*/
                {"data": "machineCode"},
                {"data": "msign"},
                {"data": "mobilePhone"},
                {"data": "printName"},
                {"data": "createtime"},
                {"data": "name"}
            ],
            aoColumnDefs: [//列定义
                /*{
                 "aTargets": [0],
                 "mData": "id",
                 "mRender": function (data, type, full) {//全部列值可以通过full.列名获取,一般单个列值用data PS:这里的render是有多少列就执行多少次方法。。。不知道为啥
                 return "";
                 }
                 },{
                    "aTargets": [0],
                    "mData": "id",
                    "mRender": function (data, type, full) {//全部列值可以通过full.列名获取,一般单个列值用data PS:这里的render是有多少列就执行多少次方法。。。不知道为啥
                        return "<input type='checkbox' name='ids' value="+data+">";
                    }
                },*/ {
                    "aTargets": [0],
                    "mData": "machineCode",
                    "mRender": function (data, type, full) {//全部列值可以通过full.列名获取,一般单个列值用data PS:这里的render是有多少列就执行多少次方法。。。不知道为啥
                        return data;
                    }
                }, {
                    "aTargets": [1],
                    "mData": "msign",
                    "mRender": function (data, type, full) {//全部列值可以通过full.列名获取,一般单个列值用data PS:这里的render是有多少列就执行多少次方法。。。不知道为啥
                        return data;
                    }
                }, {
                    "aTargets": [2],
                    "mData": "mobilePhone",
                    "mRender": function (data, type, full) {//全部列值可以通过full.列名获取,一般单个列值用data PS:这里的render是有多少列就执行多少次方法。。。不知道为啥
                        return data;
                    }
                }, {
                    "aTargets": [3],
                    "mData": "printName",
                    "mRender": function (data, type, full) {//全部列值可以通过full.列名获取,一般单个列值用data PS:这里的render是有多少列就执行多少次方法。。。不知道为啥
                        return data;
                    }
                }, {
                    "aTargets": [4],
                    "mData": "createtime",
                    "mRender": function (data, type, full) {//全部列值可以通过full.列名获取,一般单个列值用data PS:这里的render是有多少列就执行多少次方法。。。不知道为啥
                        return data;
                    }
                }, {
                    "aTargets": [5],
                    "mData": "name",
                    "mRender": function (data, type, full) {//全部列值可以通过full.列名获取,一般单个列值用data PS:这里的render是有多少列就执行多少次方法。。。不知道为啥
                        return data;
                    }
                }, {
                    "aTargets": [6],
                    "mData": "id",
                    "mRender": function (data, type, full) {//全部列值可以通过full.列名获取,一般单个列值用data PS:这里的render是有多少列就执行多少次方法。。。不知道为啥
                        /*return "<a title='删除' style='text-decoration:none' onclick='deletePrintInfo(this,"+data+")' href='javascript:;' class='c-success'>删除</a><br>";;*/
                        if(full.deletestatus==false){
                            return "<a style='text-decoration:none' onclick='deleteStatus(1,"+data+")' href='javascript:;' class='c-success'>启用</a><br>";;
                        }else{
                            return "<a style='text-decoration:none' onclick='deleteStatus(0,"+data+")' href='javascript:;' class='c-success'>禁用</a><br>";;
                        }
                    }
                }
            ],
            language: {
                aria: {
                    sortAscending: ": activate to sort column ascending",
                    sortDescending: ": activate to sort column descending"
                },
                emptyTable: "没有数据",
                info: "从 _START_ 到 _END_ 共 _TOTAL_ 条",
                infoEmpty: "没有数据",
                infoFiltered: "(0 到 _MAX_ 条)",
                lengthMenu: " _MENU_",
                search: "查询:",
                zeroRecords: "没有数据",
                paginate: {previous: "<", next: ">", last: "最后一页", first: "第一页"}
            }
        })
    }

    function query() {
        queryList();
    }

    function deletePrintInfo(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: '${pageContext.request.contextPath }/rest/printinfo/deletePrintinfo',
                dataType: 'json',
                data:{
                    ids : id
                },
                success: function(data){
                    if (data.success) {
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000});
                    }else {
                        layer.alert("删除失败");
                    }
                },
                error:function(data) {
                    layer.alert('error!',{icon:1,time:1000});
                },
            });
        });
    }

    function deleteStatus(obj,id){
        var deleteStatus;
        if(obj==1){
            deleteStatus=true;
        }else{
            deleteStatus=false;
        }
        $.ajax({
            type: 'POST',
            url: '${pageContext.request.contextPath }/rest/printinfo/deleteStatus',
            dataType: 'json',
            data:{
                "id" : id,
                "deletestatus":deleteStatus
            },
            success: function(data){
                queryList();
            },
            error:function(data) {
                layer.alert('error!',{icon:1,time:1000});
            },
        });
    }

</script>

